package com.csit.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name="T_Product",uniqueConstraints={@UniqueConstraint(columnNames={"productCode","shopID"})})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Product implements Serializable {

	private static final long serialVersionUID = -3858592455669577540L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer productID;
	
	@Column(length=50)
	private String productCode;
	
	@Column(length=500)
	private String productName;
	
	@Column(length=255)
	private String productSize;
	
	private Double productPrice;
	
	@Column(precision=2)
	private Double currentQuantity;
	
	@Column(length=1000)
	private String note;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="productItemID")
	private DataDictionary productItem;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="unitID")
	private DataDictionary unit;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="shopID",updatable=false)
	private DataDictionary shop;
	
	public Integer getProductID() {
		return productID;
	}

	public void setProductID(Integer productID) {
		this.productID = productID;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getProductSize() {
		return productSize;
	}

	public void setProductSize(String productSize) {
		this.productSize = productSize;
	}

	public Double getProductPrice() {
		return productPrice;
	}

	public void setProductPrice(Double productPrice) {
		this.productPrice = productPrice;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public DataDictionary getProductItem() {
		return productItem;
	}

	public void setProductItem(DataDictionary productItem) {
		this.productItem = productItem;
	}

	public DataDictionary getUnit() {
		return unit;
	}

	public void setUnit(DataDictionary unit) {
		this.unit = unit;
	}
	
	public DataDictionary getShop() {
		return shop;
	}

	public void setShop(DataDictionary shop) {
		this.shop = shop;
	}
	
	public Double getCurrentQuantity() {
		return currentQuantity;
	}

	public void setCurrentQuantity(Double currentQuantity) {
		this.currentQuantity = currentQuantity;
	}
	
	@Transient
	public Integer getProductItemID(){
		if(productItem==null){
			return null;
		}
		return productItem.getDataDictionaryID();
	}
	@Transient
	public String getProductItemName(){
		if(productItem==null){
			return null;
		}
		return productItem.getDataDictionaryName();
	}
	@Transient
	public Integer getUnitID(){
		if(unit==null){
			return null;
		}
		return unit.getDataDictionaryID();
	}
	@Transient
	public String getUnitName(){
		if(unit==null){
			return null;
		}
		return unit.getDataDictionaryName();
	}
	@Transient
	public void setProductItemID(Integer productItemID){
		if(productItem==null){
			productItem = new DataDictionary();
		}
		productItem.setDataDictionaryID(productItemID);
	}
	@Transient
	public void setUnitID(Integer unitID){
		if(unit==null){
			unit = new DataDictionary();
		}
		unit.setDataDictionaryID(unitID);
	}
	
}
